package com.ruoyi.mobile.project.ums.service;

import com.github.pagehelper.PageHelper;
import com.ruoyi.db.ums.domain.UmsSearchHistory;
import com.ruoyi.db.ums.domain.query.UmsSearchHistoryQueryVo;
import com.ruoyi.db.ums.mapper.UmsSearchHistoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class WxUmsSearchHistoryService
{
    @Autowired
    private UmsSearchHistoryMapper searchHistoryMapper;

    /**
     * 添加商品搜索历史
     *
     * @author 张涛
     * @param searchHistory
     */
    public void save(UmsSearchHistory searchHistory)
    {
        searchHistory.setAddTime(LocalDateTime.now());
        searchHistory.setUpdateTime(LocalDateTime.now());
        searchHistoryMapper.insertUmsSearchHistory(searchHistory);
    }

    /**
     * 根据用户id获取搜索历史
     *
     * @author 张涛
     * @param uid
     * @return
     */
    public List<UmsSearchHistory> queryByUid(Long uid)
    {
        UmsSearchHistoryQueryVo umsSearchHistoryQueryVo = new UmsSearchHistoryQueryVo();
        umsSearchHistoryQueryVo.setUserId(uid);
        return searchHistoryMapper.selectUmsSearchHistoryListByUid(umsSearchHistoryQueryVo);
    }

    /**
     * 根据用户id删除搜索历史
     *
     * @author 张涛
     * @param uid
     */
    public int deleteByUid(Long uid)
    {
        UmsSearchHistoryQueryVo umsSearchHistoryQueryVo = new UmsSearchHistoryQueryVo();
        umsSearchHistoryQueryVo.setUserId(uid);
        return searchHistoryMapper.deleteUmsSearchHistoryListByUid(umsSearchHistoryQueryVo);
    }

    public List<UmsSearchHistory> querySelective(Long userId, String keyword, Integer page, Integer size, String sort, String order)
    {
        return null;
    }
}
